package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.pojo.Order;
import com.itheima.pojo.OrderAddress;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface OrderDao {
    Page<OrderAddress> selectAllByName(String queryString);

    @Insert("insert into t_address values(null,#{name},#{telephone},#{latitude},#{imageUrl},#{address})")
    void add(OrderAddress orderAddress);

    void updateOne(OrderAddress orderAddress);

    @Select("select * from t_order_address oa,t_order o where oa.address_id = #{id} and oa.order_id = o.id")
    List<Order> findById(int id);

    @Delete("delete from t_address where id = #{id}")
    void deleteById(int id);

    @Select("select * from t_address where address like concat('%',#{s},'%')")
    List<OrderAddress> findByName(String s);

    @Insert("insert into t_order_address values(#{order_id},#{address_id})")
    void addAddressAndOrder(@Param("order_id") Integer oid, @Param("address_id") Integer aid);

    @Select("select * from t_address")
    List<OrderAddress> findAll();

    @Select("select * from t_address where id = #{id}")
    OrderAddress findNameAndAddress(int id);
}
